package ${packageName}.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class WebLogAspectAopConfig {
    private Logger log = LoggerFactory.getLogger(getClass());
    /**
     * 自定义 @MethodLog 切点
     */
    @Pointcut("@annotation(${packageName}.annonations.MethodLog)")
    public void MethodLog() {
    }

    @Before("MethodLog()")
    public void doBefore(JoinPoint joinPoint) {
        log.info("Request Method:{}, Request Param:{}", joinPoint.getSignature(), JSON.toJSONString(joinPoint.getArgs()));
    }

    @AfterReturning(returning = "o", pointcut = "MethodLog()")
    public void doAfterReturning(Object o) {
        log.info("Response Result:{}", JSONObject.toJSONString(o));
    }
}
